package com.zhangxun.domain;

import cn.hutool.http.HttpStatus;
import lombok.Data;

/**
 * 统一的封装返回数据的对象
 */
@Data
public class AjaxResult {

    private String message;
    private boolean success;
    private Object data;
    private Integer code;


    public static AjaxResult ok (){
        AjaxResult result = new AjaxResult();
        result.setCode(HttpStatus.HTTP_OK);
        result.setSuccess(true);
        return result;
    }

    public static AjaxResult ok (String message){
        AjaxResult result = new AjaxResult();
        result.setCode(HttpStatus.HTTP_OK);
        result.setSuccess(true);
        result.setMessage(message);
        return result;
    }

    public AjaxResult ok(Object data){
        AjaxResult result = new AjaxResult();
        result.setCode(HttpStatus.HTTP_OK);
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static AjaxResult error (String message){
        AjaxResult result = new AjaxResult();
        result.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
        result.setSuccess(false);
        result.setMessage(message);
        return result;
    }

    public AjaxResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public AjaxResult setData(Object data) {
        this.data = data;
        return this;
    }

    public AjaxResult setCode(Integer code) {
        this.code = code;
        return this;
    }
}
